#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<pthread.h>

//function 
void *thread_run(void* arg)
{
  pthread_detach(pthread_self());// 线程分离
  while(1)
  {
      printf("%s, %lu, pid:%d\n",(char*)arg,pthread_self(),getpid());
      sleep(1);
      break;
  }
  //pthread_exit((void*)10);
  return (void*)10;
}

int main()
{
  pthread_t tid;
  pthread_create(&tid,NULL,thread_run,"thread 1");

  printf("main :%lu, pid %d\n",pthread_self(),getpid());

  sleep(10);
  pthread_cancel(tid);
  printf("new thread %lu be canceled!\n",tid);

  void* ret = NULL;
  pthread_join(tid,&ret);
  printf("thread quit code : %d \n",(long long)ret);
  return 20;
}
